package cn.qw.springbootjpa.controller;

import cn.qw.springbootjpa.pojo.User;
import cn.qw.springbootjpa.repostory.UserRepostory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
public class UserController {
    @Autowired
    private UserRepostory repostory;

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id") Integer id) {
        Optional<User> byId = repostory.findById(id);
        return byId.get();
    }

    @GetMapping("/user")
    public User add(User user) {
        User save = repostory.save(user);
        return save;
    }

}
